`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 2024/07/06 09:55:32
// Design Name: 
// Module Name: imm
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////


module imm(
    data2,imm_inst1,imm_inst2,imm_inst3,imm_inst4,op_imm,sextend_imm,data_imm
    );

    input [31:0] data2;
    input [11:0] imm_inst1;
    input [6:0] imm_inst2;
    input [4:0] imm_inst3;
    input [19:0] imm_inst4;
    input [2:0] op_imm;
    output reg [31:0] sextend_imm;
    output reg [31:0] data_imm;

    parameter R_type=0,I_type=1,S_type=2,B_type=3,J_type=4;

    always @(*) begin
        case (op_imm)
            R_type : begin 
                sextend_imm = data2;
                data_imm = sextend_imm;
            end
            I_type : begin
                sextend_imm = {{20{imm_inst1[11]}},imm_inst1};
                data_imm = sextend_imm;
            end
            S_type : begin
                sextend_imm = {{20{imm_inst2[6]}},imm_inst2,imm_inst3};
                data_imm = sextend_imm;
            end
            B_type : begin
                sextend_imm = {{20{imm_inst2[6]}},imm_inst3[0],imm_inst2[5:0],imm_inst3[4:1],1'b0};
                // sextend_imm = {32'b1000};
                data_imm = data2;
            end
            J_type : begin
                sextend_imm = {{12{imm_inst4[19]}},imm_inst4[7:0],imm_inst4[8],imm_inst4[18:9],1'b0};
                data_imm = sextend_imm;
            end
            default : begin
                sextend_imm = data2;
                data_imm = sextend_imm;
            end
        endcase
    end
endmodule
